package com.shop2cn.iapi.accounting.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.accounting.parameter.AccountBean;
import com.shop2cn.iapi.accounting.parameter.GetAccountByUserIdBean;
import com.shop2cn.iapi.accounting.service.GetAccountByUserIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.Account;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*根据用户编号及账户类型获取账户信息接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAccountByUserId{
	private static GetAccountByUserIdBean getaccountbyuseridBean;
	private static GetAccountByUserIdCall getaccountbyuseridCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户编号获取账户信息接口");
	}

	@Before
	public void caseUp() {
		getaccountbyuseridBean=new GetAccountByUserIdBean();
		getaccountbyuseridCall=new GetAccountByUserIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaccountbyuseridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAccountByUserId_001() {
		Logger.start(true,"根据用户编号获取账户信息成功");
		try {
			int userId=21000000;
			int accountType=1;
			getaccountbyuseridBean.setUserId(userId);
			getaccountbyuseridBean.setAccountType(accountType);
			getaccountbyuseridBean.setAppId("AutoTest");
			getaccountbyuseridCall.setData(getaccountbyuseridBean);
			getaccountbyuseridCall.callService();			
			List<Account> aids= new AccountWapper().selectAccountInfoByUserId(userId,accountType);			
			AccountBean account=getaccountbyuseridCall.getReturnAccount();				
			Logger.verifyEquals((Integer)aids.get(0).getUserId(),account.getUserId(),"验证接口返回userid跟数据库是否一致");	
			Logger.verifyEquals((Integer)aids.get(0).getStatus(),account.getStatus(),"验证接口返回Action跟数据库是否一致");	
			Logger.verifyEquals((Integer)aids.get(0).getCurrencyType(),account.getCurrencyType(),"验证接口返回CurrencyType跟数据库是否一致");	
			Logger.verifyEquals((Integer)aids.get(0).getAccountType(),account.getAccountType(),"验证接口返回AccountType跟数据库是否一致");	
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getAvailAmount()).compareTo(account.getAvailAmount()),"验证接口返回AvailAmount:"+account.getAvailAmount()+"跟数据库是否一致");
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getFreezeAmount()).compareTo(account.getFreezeAmount()),"验证接口返回FreezeAmount:"+account.getFreezeAmount()+"跟数据库是否一致");			
			Logger.verifyEquals((String)aids.get(0).getAccountId(),account.getAccountId(),"验证接口返回AccountInfoId跟数据库是否一致");			
			
			String ct=YMTDateUtil.getFormatTime(aids.get(0).getCreateTime(), YMTDateUtil.YMDHMSS);
			Logger.verifyEquals(ct.substring(0, 19), account.getCreateTime().substring(0, 19),
					"验证接口返回CreateTime跟数据库是否一致");
			String ut=YMTDateUtil.getFormatTime(aids.get(0).getUpdateTime(), YMTDateUtil.YMDHMSS);
			Logger.verifyEquals(ut.substring(0, 19), account.getUpdateTime().substring(0, 19),
					"验证接口返回UpdateTime跟数据库是否一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountByUserId_002() {
		Logger.start(false,"用户编号不存在,返回空");
		try {
			int userId=0;
			getaccountbyuseridBean.setUserId(userId);
			getaccountbyuseridBean.setAppId("AutoTest");
			getaccountbyuseridBean.setAccountType(0);
			getaccountbyuseridCall.setData(getaccountbyuseridBean);
			getaccountbyuseridCall.callService();			
			Logger.verifyEquals("null",getaccountbyuseridCall.getData(),"验证接口返回data为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountByUserId_003() {
		Logger.start(false,"账户类型不存在,获取账户失败");
		try {
			int userId=20000001;
			int accountType=1;
			getaccountbyuseridBean.setUserId(userId);
			getaccountbyuseridBean.setAppId("AutoTest");
			getaccountbyuseridBean.setAccountType(accountType);
			getaccountbyuseridCall.setData(getaccountbyuseridBean);
			getaccountbyuseridCall.callService();			
			Logger.verifyEquals("null",getaccountbyuseridCall.getData(),"验证接口返回data为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountByUserId_004() {
		Logger.start(false,"用户编号为空,返回空");
		try {
			int accountType=1;
			//getaccountbyuseridBean.setUserId(userId);
			getaccountbyuseridBean.setAppId("AutoTest");
			getaccountbyuseridBean.setAccountType(accountType);
			getaccountbyuseridCall.setData(getaccountbyuseridBean);
			getaccountbyuseridCall.callService();			
			Logger.verifyEquals("null",getaccountbyuseridCall.getData(),"验证接口返回data为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountByUserId_005() {
		Logger.start(true,"账户类型为空,默认账户类型为1");
		try {
			int userId=21000002;
			getaccountbyuseridBean.setUserId(userId);
			getaccountbyuseridBean.setAppId("AutoTest");
			//getaccountbyuseridBean.setAccountType(accountType);
			getaccountbyuseridCall.setData(getaccountbyuseridBean);
			getaccountbyuseridCall.callService();			
			List<Account> aids= new AccountWapper().selectAccountInfoByUserId(userId,1);			
			AccountBean account=getaccountbyuseridCall.getReturnAccount();				
			Logger.verifyEquals((Integer)aids.get(0).getUserId(),account.getUserId(),"验证接口返回userid跟数据库是否一致");	
			Logger.verifyEquals((Integer)aids.get(0).getStatus(),account.getStatus(),"验证接口返回Action跟数据库是否一致");	
			Logger.verifyEquals((Integer)aids.get(0).getCurrencyType(),account.getCurrencyType(),"验证接口返回CurrencyType跟数据库是否一致");	
			Logger.verifyEquals((Integer)aids.get(0).getAccountType(),account.getAccountType(),"验证接口返回AccountType跟数据库是否一致");	
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getAvailAmount()).compareTo(account.getAvailAmount()),"验证接口返回AvailAmount:"+account.getAvailAmount()+"跟数据库是否一致");
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getFreezeAmount()).compareTo(account.getFreezeAmount()),"验证接口返回FreezeAmount:"+account.getFreezeAmount()+"跟数据库是否一致");			
			Logger.verifyEquals((String)aids.get(0).getAccountId(),account.getAccountId(),"验证接口返回AccountInfoId跟数据库是否一致");			
			
			String ct=YMTDateUtil.getFormatTime(aids.get(0).getCreateTime(), YMTDateUtil.YMDHMSS);
			Logger.verifyEquals(ct.substring(0, 19), account.getCreateTime().substring(0, 19),
					"验证接口返回CreateTime跟数据库是否一致");
			String ut=YMTDateUtil.getFormatTime(aids.get(0).getUpdateTime(), YMTDateUtil.YMDHMSS);
			Logger.verifyEquals(ut.substring(0, 19), account.getUpdateTime().substring(0, 19),
					"验证接口返回UpdateTime跟数据库是否一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountByUserId_006() {
		Logger.start(false,"Appid为空,获取账户失败");
		try {
			int userId=20000001;
			int accountType=1;
			getaccountbyuseridBean.setUserId(userId);
			//getaccountbyuseridBean.setAppId("AutoTest");
			getaccountbyuseridBean.setAccountType(accountType);
			getaccountbyuseridCall.setData(getaccountbyuseridBean);
			getaccountbyuseridCall.callService();			
			Logger.verifyEquals("null",getaccountbyuseridCall.getData(),"验证接口返回data为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}